/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Relatorio_vendedor.java
 *
 * Created on 18/06/2011, 01:47:50
 */

package formularios;

import groovyjarjarcommonscli.ParseException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFormattedTextField;
import javax.swing.text.MaskFormatter;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Ramon
 */
public class Relatorio_vendedor extends javax.swing.JInternalFrame {

    /** Creates new form Relatorio_vendedor */
    public Relatorio_vendedor() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btn_gerar_relatorio = new javax.swing.JButton();
        cpf_vendedor = new javax.swing.JTextField();

        btn_gerar_relatorio.setText("jButton1");
        btn_gerar_relatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_gerar_relatorioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(117, 117, 117)
                        .addComponent(cpf_vendedor, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addComponent(btn_gerar_relatorio)))
                .addContainerGap(138, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(cpf_vendedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btn_gerar_relatorio)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_gerar_relatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_gerar_relatorioActionPerformed
        try {

            String reportName = "report1.jasper";
            InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);
            Class.forName("org.apache.derby.jdbc.ClientDriver");

            Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/BancoImobiliaria", "app", "app");
            HashMap parametros = new HashMap();
            parametros.put("cpf_vendedor", cpf_vendedor.getText());
            JasperPrint jasperPrint = JasperFillManager.fillReport(is, parametros, conn);
     //       JasperExportManager.exportReportToPdfFile(jasperPrint, "/home/fabrizzio/teste.pdf");
     //       JasperPrintManager.printReport(jasperPrint, true);
            JasperViewer jv = new JasperViewer(jasperPrint);
            jv.setVisible(true);

        } catch (JRException ex) {
          //  Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
          //  Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
           // Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btn_gerar_relatorioActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_gerar_relatorio;
    private javax.swing.JTextField cpf_vendedor;
    // End of variables declaration//GEN-END:variables

}
